package org.shoukaiseki.common.utils

import org.shoukaiseki.common.exception.VerificationException

object VerificationUtils {

    /**
     * 如果 expression 为 false 则抛异常
     */
    fun falseToThrow(expression: Boolean, msg: String?, vararg params: Any) {
        if (!expression) {
            throw VerificationException(msg).format(*params)
        }
    }

    /**
     * 如果 expression 为 true 则抛异常
     */
    fun trueToThrow(expression: Boolean, msg: String?, vararg params: Any) {
        if (expression) {
            throw VerificationException(msg).format(*params)
        }
    }


    /**
     * 对象如果为空
     * @param obj
     * @param msg
     */
    fun nullToThrow(obj: Any?, msg: String?, vararg params: Any) {
        if (obj == null) {
            throw VerificationException(msg).format(*params)
        }
    }

    /**
     * 对象如果为空则抛异常
     * @param collection
     * @param msg   异常提示
     */
    fun emptyToThrow(collection: Collection<*>?, msg: String?, vararg params: Any) {
        if (collection == null || collection.size == 0) {
            throw VerificationException(msg).format(*params)
        }
    }
}
